package com.macro.mall.product.service.impl;


import com.macro.mall.mapper.*;
import com.macro.mall.model.*;
import com.macro.mall.product.service.PmProdSpecSkuService;
import io.micrometer.core.instrument.util.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

@Slf4j
@Service
public class PmProdSpecSkuServiceImpl implements PmProdSpecSkuService {
    @Autowired
    private PmSpecSkuMapper pmSpecSkuMapper;
    @Autowired
    private PmSpecPricePlanPrptyRelMapper pmSpecPricePlanPrptyRelMapper;


    public List<PmSpecSku> getSpecSkuList(PmSpecSku pmSpecSku) {
        PmSpecSkuExample skuExample = new PmSpecSkuExample();
        PmSpecSkuExample.Criteria skuCriteria = skuExample.createCriteria();
        skuCriteria.andProdSpecIdEqualTo(pmSpecSku.getProdSpecId());
        if(!StringUtils.isBlank(pmSpecSku.getStatus())){
            skuCriteria.andStatusEqualTo(pmSpecSku.getStatus());
        }
        if(!StringUtils.isBlank(pmSpecSku.getCode())){
            skuCriteria.andCodeEqualTo(pmSpecSku.getCode());
        }
        skuExample.setOrderByClause(" seq asc ");
        List<PmSpecSku> specSkuList = pmSpecSkuMapper.selectByExample(skuExample);
        if (specSkuList != null && specSkuList.size() > 0) {
            PmSpecPricePlanPrptyRelExample relExample;
            PmSpecPricePlanPrptyRelExample.Criteria relCriteria;
            List<PmSpecPricePlanPrptyRel> pmSpecPricePlanPrptyRelList;
            for (PmSpecSku pmSpecSkuInfo : specSkuList) {
                relExample = new PmSpecPricePlanPrptyRelExample();
                relCriteria = relExample.createCriteria();
                relCriteria.andSkuIdEqualTo(pmSpecSkuInfo.getId());
                relExample.setOrderByClause(" seq asc ");
                pmSpecPricePlanPrptyRelList = pmSpecPricePlanPrptyRelMapper.selectByExample(relExample);
                pmSpecSkuInfo.setSpecPricePlanPrptyRelList(pmSpecPricePlanPrptyRelList);
            }
        }
        return specSkuList;
    }
}